import { Inject, Injectable } from '@nestjs/common';
import { Neo4jService } from '../neo4j/neo4j.service';

@Injectable()
export class AppService {
  @Inject(Neo4jService)
  private readonly neo4jService: Neo4jService;
  async getData(): Promise<{ message: string }> {
    // this is no good practice, but it demonstrates how to connect to a neo4j database
    const driver = this.neo4jService.getDriver();
    const session = driver.session()
    const personName = 'Alice'
    try {
      const result = await session.run(
        'CREATE (a:Person {name: $name}) RETURN a',
        { name: personName }
      )

      const singleRecord = result.records[0]
      const node = singleRecord.get(0)
      return { message: 'Wrote name to db: ' + node.properties.name + '. You can connect to localhost:7687 with username=neo4j and password=password in the neo4j desktop app and check it out. You can find the app here: https://neo4j.com/download/.' };
    } finally {
      await session.close()
    }
  }

  //write endpoints for crud operations to a neo4j database which is running on localhost:7687
  //use the neo4j-driver package to connect to the database
  //use the @nestjs/neo4j package to connect to the database
}
